<template>
  <el-dialog :title="title" :close-on-click-modal="false" :fullscreen="true" :visible.sync="visible"
    :before-close="cancel" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="50%">
    <el-row class="JNPF-common-search-box" :gutter="16">
      <el-form @submit.native.prevent ref="elForm" :model="dataForm" :rules="rules">
        <el-col :span="4">
          <el-form-item label="单据编号" prop="FBILLNO">
            <el-input v-model="dataForm.FBILLNO" placeholder="自动生成" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="加盟商" prop="FCUSTOMNO">
            <el-select v-model="dataForm.FCUSTOMNO" placeholder="请选择" :disabled="$store.getters.userInfo.manufacturer">
              <el-option v-for="item in formationlist" :key="item.FCUSTOMNO" :label="item.FCUSTOMNAME"
                :value="item.FCUSTOMNO">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="验收日期" prop="FBILLCREDATE">
            <el-date-picker v-model="dataForm.FBILLCREDATE" value-format="yyyy-MM-DD" type="date" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="">
            <el-button type="success" icon="el-icon-plus" @click="insert">添加一行</el-button>
            <!-- <el-button type="primary" @click="DlvCreate" :loading="loading" v-if="insertorupdate">保存</el-button> -->
            <el-button type="primary" :loading="loading">保存</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <el-table :data="list" border stripe>
      <el-table-column label="操作" width="80">
        <template slot-scope="scope">
          <el-button slot="reference" icon="el-icon-delete" style="color: red" @click="shopdate(scope.$index)"
            type="text">删除</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="FITEMNO" label="商品编号" width="200">
      </el-table-column>
      <el-table-column prop="FITEMNAME" label="商品名称"></el-table-column>
      <el-table-column prop="FSPEC" label="商品规格" width="90"></el-table-column>
      <el-table-column prop="FORDUNIT" label="订货单位" width="90"></el-table-column>
      <el-table-column prop="FORDPACK" label="订货系数" width="90"></el-table-column>
      <el-table-column prop="FSELLPRICE" label="配送价" width="90"></el-table-column>
      <el-table-column prop="FORDQTY" label="订货件数" width="100">
      </el-table-column>
      <el-table-column prop="FDISQTY" label="配送数量" width="100">
      </el-table-column>
      <el-table-column prop="FRECQTY" label="验收数量" width="150">
        <template slot-scope="scope">
          <el-input placeholder="请输入内容" v-model="scope.row.FRECQTY" class="input-with-select">
          </el-input>
        </template>
      </el-table-column>
      <el-table-column prop="fdisprice" label="含税金额" width="90">
        <template slot-scope="scope">
          {{parseFloat(scope.row.FRECQTY*scope.row.FSELLPRICE).toFixed(2)}}
        </template>
      </el-table-column>
    </el-table>
    <ShopqueryFcuston ref="ShopqueryFcuston" @confirm="shoplist" />
  </el-dialog>
</template>
<script>
  import ShopqueryFcuston from "@/components/ShopqueryFcuston/ShopqueryFcuston.vue"
  import jnpf from "@/utils/jnpf"
  export default {
    components: { ShopqueryFcuston },
    props: {
      formationlist: {
        type: Array,
        default: [],
      },
    },
    data() {
      return {
        title: "新增",
        insertorupdate: true,
        dataForm: {
          FBILLNO: "",
          FCUSTOMNO: "",
          FBILLCREDATE: jnpf.dateFormat(new Date(), "YYYY-MM-DD"),
          FDISDATE: jnpf.dateFormat(new Date(), "YYYY-MM-DD"),
          FDISTYPE: 0,
          FITEMCOUNT: 0,
          FPIECECOUNT: 0,
          FDISAMT: 0,
          FTOTNOAMT: 0,
          FTOTTAXAMT: 0,
          FTOTAMT: 0,
          FPROMAMT: 0,
          FPAYBILLNO: "",
          FPAYAMT: 0,
          FSALEER: "",
          FSRCBILLNO: "",
          FEXPLANATION: "",
          FBILLTYPE: 0,
          FBILLSTATE: 1,
          FOPERATOR: "",
          FOPERDATE: "",
          FCHECKER: "",
          FCHECKDATE: "",
          F_TENANT_ID: "",
          F_FLOW_ID: "",
          F_FLOW_TASK_ID: ""
        },
        rules: {
          FCUSTOMNO: [
            { required: true, message: '请选择供应商', trigger: 'blur' },
          ],
          FBILLCREDATE: [
            { required: true, message: '请输入验收日期', trigger: 'blur' },
          ],
        },
        list: [],
        loading: false,
        visible: false,
      };
    },
    created() {
    },
    mounted() { },
    methods: {
      //
      init(FBILLNO) {
        this.dataForm.FBILLNO = FBILLNO;
        if (this.dataForm.FBILLNO) {
          this.title = "修改"
          this.insertorupdate = false;
        }
        else {
          this.title = "新增"
          this.dataForm.FBILLNO = "K" + Math.floor(Math.random() * 10000000) + 1;
          this.insertorupdate = true;
        }
        this.visible = true;
      },
      insert() {
        this.$refs.ShopqueryFcuston.open();
      },
      shoplist(data) {
        data.forEach(item => {
          this.list.push({
            FBILLNO: this.dataForm.FBILLNO
            , FENTRYID: ""
            , FITEMNO: item.FITEMNO
            , FITEMNAME: item.FITEMNAME
            , FORDPACK: item.FORDPACK
            , FORDUNIT: item.FORDUNIT
            , FSPEC: item.FSPEC
            , FORDQTY: "0"
            , FSALEUNIT: ""
            , FQTYBASE: ""
            , FPROMPRICE: ""
            , FPROMNO: ""
            , FDISPRICE: ""
            , FSELLPRICE: ""
            , FDISQTY: "0"
            , FRECQTY: "0"
            , FNOAMT: ""
            , FTAXAMT: 0
            , FAMT: 0
            , FPROMAMT: 0
            , FMEMO: 0
            , F_TENANT_ID: 0
          })
        });
      },
      //
      cancel() {
        this.$refs.elForm.resetFields();
        this.list = [];
        this.visible = false;
      },
    },
  };
</script>